﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Modeling_Sub_Pages_NewsPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        UniversityDatabaseManagerment udm = new UniversityDatabaseManagerment();

        if (Session["WelcomeUser"] != null)
        {
            if (Session["EmployeeID"] != null && Session["Role"].ToString().Equals("ADM"))
            {
                if (udm.createConnection() != null)
                {
                    GridView1.DataSource = udm.showAchievementForMaintain(udm.createConnection());
                    GridView1.DataBind();
                }
                else
                {
                    Response.Redirect("~/ErrorPage.aspx");
                }
            }
            else
            {
                Response.Redirect("~/LoginMessage.aspx?id=1");
            }
        }
        else
        {
            Response.Redirect("~/Login.aspx?id=2");
        }
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[3].Text.ToString());

        UniversityDatabaseManagerment udm = new UniversityDatabaseManagerment();

        if (!udm.removeAchievement(udm.createConnection(), id))
        {
            Response.Redirect("~/ErrorPage.aspx");
        }

        if (udm.createConnection() != null)
        {
            GridView1.DataSource = udm.showAchievementForMaintain(udm.createConnection());
            GridView1.DataBind();
        }
        else
        {
            Response.Redirect("~/ErrorPage.aspx");
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // reference the Delete LinkButton
            LinkButton db = (LinkButton)e.Row.Cells[2].Controls[0];

            int id = Convert.ToInt32(e.Row.Cells[3].Text.ToString());

            db.OnClientClick = string.Format("return confirm('Are you certain you want to delete the Achievement ID = {0}?')",id);
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
}